package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.NestedRecyclerView;
import com.mz.ozy.R;
import com.mz.ozy.bean.ShopSpecListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GoodsDetailSpecAdapter extends RecyclerView.Adapter<GoodsDetailSpecAdapter.MyViewHolder> {


    private Context mContext;
    private TagAdapter mTagAdapter;
    List<ShopSpecListBean.ShopSpecBean> mSpecBeanList;

    public String[] initSelctGoodsspec;

    public GoodsDetailSpecAdapter(Context context, List<ShopSpecListBean.ShopSpecBean> mSpecBeanList) {
        this.mContext = context;
        this.mSpecBeanList = mSpecBeanList;
    }

    public void setInitSelctGoodsspec(String goodsspec) {
        this.initSelctGoodsspec = goodsspec.split(",");
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_spec, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ShopSpecListBean.ShopSpecBean bean = mSpecBeanList.get(position);
        holder.mSpectTitle.setText(bean.getName());
//        List<SpecBean> beanList = specValuesMaps.get(bean.getId());
//        mTagAdapter = new TagAdapter(mContext, beanList, initSelctGoodsspec[position], bean.getId(), new TagAdapter.OnItemClickListener() {
//            @Override
//            public void OnItemClick(String id, String i) {
//                selectMaps.put(id, i);
//                if (selectMaps.size() == mSpecBeanList.size()) {
//                    EventBus.getDefault().postSticky(selectMaps);
//                }
//            }
//        });
        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        holder.mFlowTagLayout.setLayoutManager(flowLayoutManager);
        holder.mFlowTagLayout.setAdapter(mTagAdapter);


    }

    @Override
    public int getItemCount() {
        return mSpecBeanList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.spectTitle)
        TextView mSpectTitle;
        @BindView(R.id.flowTagLayout)
        NestedRecyclerView mFlowTagLayout;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
